package com.example.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.annotations.*;
import com.example.auth.model.UserModel;
import com.example.auth.service.UserModelService;
import com.example.db.DBSql;
import com.example.service.ExampleService;
import com.example.utils.Results;

import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * @Classname ExampleController
 * @Description TODO
 * @Date 2022/7/26 12:41
 * @Created by XiongXiong
 * @Author: X.I.O
 */
@RestController("/people")
public class ExampleController {

    @Autowired
    DBSql dbSql;

    @Autowired
    UserModelService userModelService;

    @Autowired
    private ExampleService exampleService;

    @GetMapping("/demo")
    public JSONObject demoController(){
        return Results.success("哈哈11111");
    }

    @GetMapping("/sql")
    public JSONObject getSql(@Param("page")Integer pageNum,
                             @Param("pageSize")Integer pageSize,
                             @Param(value = "num",required = false)Double doubleNum,
                             @Param(value = "num1",required = false)Float numberNum,
                             @Param(value = "date3",required = false)Date date){
        int page=(pageNum-1)*pageSize;
       List<Map<String,Object>> mapList=dbSql.selectList("select * from sys_person limit "+page+","+pageSize);
       return Results.success(mapList);
    }

    @PostMapping("/sqltest")
    public JSONObject getSql2(@Param(value = "page",required = false)Integer page,
                              @Param(value = "json",required = false)JSONObject array){
        System.out.println(page);
        array.forEach((k,v)->{
            System.out.println(k+"  "+v);
        });
//        int page=(pageNum-1)*pageSize;
//        List<Map<String,Object>> mapList=dbSql.selectList("select * from sys_person limit "+page+","+pageSize);
        return Results.success("haha");
    }


    @PostMapping("/test")
    public JSONObject getSqlTest(@RequestBody JSONObject obj){
        obj.forEach((k,v)->{
            System.out.println(k+" "+v);
        });
//        int page=(pageNum-1)*pageSize;
//        List<Map<String,Object>> mapList=dbSql.selectList("select * from sys_person limit "+page+","+pageSize);
        return Results.success("haha");
    }

    @GetMapping("/testdemo")
    public JSONObject testDemoController(){
       List<Map<String,Object>> mapList=exampleService.selectMapList();
       return Results.success(mapList);
    }

    @PostMapping("/post")
    public JSONObject testPostTestController(){
        List<Map<String,Object>> mapList=exampleService.selectMapList();
        return Results.success(mapList);
    }



    @PostMapping("/testpost")
    public JSONObject testPostController(){
        List<Map<String,Object>> mapList=exampleService.selectMapList();
        return Results.success(mapList);
    }

    @PostMapping("/testpost2")
    public JSONObject test2PostController(){
        List<Map<String,Object>> mapList=exampleService.selectMapList();
        return Results.success(mapList);
    }

    @PostMapping("/testposttest")
    public JSONObject testpostPostController(){
        List<Map<String,Object>> mapList=exampleService.selectMapList();
        return Results.success(mapList);
    }

    @PostMapping("/testGet")
    public JSONObject testGetController(){
        List<Map<String,Object>> mapList=exampleService.selectMapList();
        return Results.success(mapList);
    }

    @PostMapping("/testGet2")
    public JSONObject testGet2Controller(){
        List<Map<String,Object>> mapList=exampleService.selectMapList();
        return Results.success(mapList);
    }

    @PostMapping("/testGet4444444")
    public JSONObject testGet3Controller(){
        List<Map<String,Object>> mapList=exampleService.selectMapList();
        return Results.success(mapList);
    }



}
